#define  _CRT_SECURE_NO_WARNINGS
#include "tree.h"
void postorder1(struct TreeNode* root, int* returnSize)
{
    if (root == NULL)
    {
        return;
    }
    postorder1(root->left, returnSize);
    postorder1(root->right, returnSize);
    (*returnSize)++;
}

void postorder2(struct TreeNode* root, int* ret, int* i)
{
    if (root == NULL)
    {
        return;
    }
    postorder2(root->left, ret, i);
    postorder2(root->right, ret, i);
    ret[(*i)++] = root->val;
}

int* postorderTraversal(struct TreeNode* root, int* returnSize)
{
    *returnSize = 0;
    postorder1(root, returnSize);
    int* ans = (int*)malloc(sizeof(int) * (*returnSize));
    int k = 0;
    postorder2(root, ans, &k);
    return ans;
}

int main()
{
    struct TreeNode* root = CreatTree();
    LevelOrder(root);
    int returnSize = 0;
    int* ans = postorderTraversal(root, &returnSize);
    for (int i = 0; i < returnSize; i++)
    {
        printf("%d ", ans[i]);
    }
    return 0;
}